import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:s_mankey/config/net/smonkey_ui_api.dart';
import 'package:s_mankey/service/smonkey_repository.dart';
import 'package:s_mankey/view_model/my_page_vmodel.dart';


/// 编辑信息时使用的cell
class EditInput extends StatefulWidget {

  Map arguments; //标题

  EditInput({@required this.arguments});


  @override
  _EditInput createState() => _EditInput();
}

class _EditInput extends State<EditInput> {

  TextEditingController _controller = TextEditingController();

  @override
  void initState() {
    print('widget.arguments: ${widget.arguments}');
    _controller.text = widget.arguments['val'];
    super.initState();
  }

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        backgroundColor: Colors.grey[200],
        appBar: AppBar(elevation: 0,
          leading: Center(
            child: GestureDetector(onTap: (){
              Navigator.pop(context);
            },child: Text('取消'),),
          ),
          title: Text(widget.arguments['title']),actions: [
            Center(child: Padding(
              padding: const EdgeInsets.only(right: 15),
              child: CupertinoButton(
                  disabledColor: Colors.grey,
                  child: Text('完成'), onPressed:(){
                    SmonkeysRepository.fetchMyEditorSave(datas: {widget.arguments['key']: _controller.text});
                    Navigator.pop(context);
              }),
            ),)
          ],),body: Column(children: [
      Container(child: Container(
        color: Colors.white,
        child: Padding(
          padding: const EdgeInsets.fromLTRB(15,0,15,0),
          child: TextField(
            obscureText: false,
            controller: _controller,
            autofocus: true,
            textCapitalization: TextCapitalization.words,
            decoration: InputDecoration(
              border: InputBorder.none,
              prefixStyle: TextStyle(color: Colors.black), ),
          ),
        ),
      ),),
    ],));
  }

}